package pl.edu.agh.jemo.gui.chart;

import java.util.ArrayList;
import java.util.List;

import pl.edu.agh.jemo.evolution.population.Population;

/**
 * Class representing single plot instance.
 * Contains all necesary information to prepare requested chart.
 * Allows plotting of multiple populations, or with background of objective function. Can be configured to prepare genotype, phenotype or both plots.
 * Created Plot object can be passed to Plotter, to create plot file.
 * 
 * @author Marcin Zbijowski
 *
 */
public class Plot {
	/**
	 * Name of plot is used to identify different plots in result folder.
	 */
	private String name = "";
	/**
	 * List of population to plot.
	 */
	private List<Population> populations = new ArrayList<Population>();
	/**
	 * Type of plot to be created, possible values are GENOTYPE, PARETO, or BOTH.
	 */
	private PlotType plotType = PlotType.BOTH;

	/**
	 * Inserts another population to a plot request.
	 * 
	 * @param population Population to plot on current plot.
	 */
	public void addPopulation(Population population) {
		populations.add(population);
	}
	
	/**
	 * Inserts prepared List of population to be added to current plot.
	 * 
	 * @param population Populations to plot on current plot.
	 */
	public void addPopulation(List<Population> population) {
		populations.addAll(population);
	}
	
	/**
	 * Returns reference to list of already added to plot populations.
	 * Can be used to add, or remove next population without keeping reference to plot object.
	 * 
	 * @return List of populations filled with populations added to current plot.
	 */
	public List<Population> getPopulations() {
		return populations;
	}

	/**
	 * Sets name for plot request.
	 * Name allow to identify plot, so it have to be unique, in a single step. Population from many steps might be plotted under the same name.
	 * It is recommended, as it allows grouping charts of one type.
	 * 
	 * @param name New name value for plot.
	 */
	public void setName(String name) {
		this.name = name;
	}
	
	/**
	 * Returns currently set name for a plot.
	 * 
	 * @return Value of name for current plot.
	 */
	public String getName() {
		return name;
	}
	
	/**
	 * Sets type of requested plot.
	 * If GENOTYPE, then population genotypes are printed, if possible with background function.
	 * If PARETO, then generates phenotype plot. For BOTH, both two charts are generated.
	 * 
	 * @param plotType Required plot type.
	 */
	public void setPlotType(PlotType plotType) {
		this.plotType = plotType;
	}
	
	/**
	 * Returns currently set plot type.
	 * 
	 * @return Value of expected plot type parameter.
	 */
	public PlotType getPlotType() {
		return plotType;
	}	
}
